-
Notifications
You must be signed in to change notification settings - Fork 28
#3057. Add pattern assignment cases to C-style for tests #3126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
A couple of tests are somewhat tricky: The description says that something is 'reachable', but I don't think the given test would actually detect whether it is reachable or unreachable.
Come to think of it, the current version of the tests could work after all because the correct analysis will give rise to no errors (more precisely: no diagnostics), and the buggy behavior that I'm hunting would give rise to a 'dead code' warning.
Anyway, please take another look and consider the issue that I described.
Thank you for the detailed analysis. Updated. PTAL.
It's an interesting about type of interest. It can be tested (in a separate PR). class S {}
class T extends S {
void foo() {}
}
test1() {
S s = S();
for (;false;) {
if (s is T) {} // make `T` a type of interest
}
s = T();
s.foo(); // Not an error.
}
test2() {
S s = S();
for (;false; s is T) {
}
s = T();
s.foo(); // Error. Not an issue, result of the conservativeJoin()? Same as https://github.com/dart-lang/sdk/issues/60320 ?
} Is this an expected that there is an error in |
The This justifies the error at the end, in the line with a long comment. |
After the testing and rereading the spec I think that there is another reason of such behavior. According to the spec:
Definition of
I think it is too general definition but the key point here is "for the purposes of promotion". So s = S();
s is T;
s = T();
s.foo(); // Error. There were no promotion above And for the same reason we are getting an error in case of S s = S();
int i = 0;
for (;false; s is T ? i++ : i += 2) {}
s = T();
s.foo(); // Ok, now accepted Please correct me the above is wrong. Otherwise it'd be nice to test type of interest in all of the places where we should have a promotion.
As far as I understand to get a promotion after the type check we should have s = S();
s is T && 2 > 1; // `true(N)` branch added to `s is T`
s = T();
s.foo(); // Now Ok! So to test types of interest we should check all of the places in the flow analysys spec where Please correct me if I'm wrong. |
The flow models associated with the evaluation of the expression I do think it's fair to say that "
That's a bug! The flow model Given that It has probably never been reported because it is a pointless statement: We're computing a boolean value and discarding it, and there are no side effects. In any case, I do believe that this is a bug.
In this case the type test
No, the point is that the
Looks like the bug that came up above doesn't apply here, probably because the |
@stereotype441, do you agree that the following is a bug?: class S {}
class T extends S {
void foo() {}
}
void main() {
var s = S();
s is T;
s = T();
s.foo(); // Error, so `T` was not a type of interest, but it should be.
} |
Yes, good catch! I've filed dart-lang/sdk#60479 to track it. And nice job with the analysis above; I walked through the code in the debugger and confirmed that what's happening is exactly what you surmised. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
2025-06-19 [email protected] dart-lang/co19#3180. Add more `js_interop` tests (dart-lang/co19#3232) 2025-06-18 [email protected] dart-lang/co19#3180. Add more JSAnyOperatorExtension tests (dart-lang/co19#3225) 2025-06-18 [email protected] dart-lang/co19#3180. Add more `JSArray` and `JSArrayBuffer` tests (dart-lang/co19#3230) 2025-06-17 [email protected] dart-lang/co19#1401. Add additional tests for shared case scoping (dart-lang/co19#3174) 2025-06-17 [email protected] dart-lang/co19#3180. Add `JSArray` tests. (dart-lang/co19#3229) 2025-06-16 [email protected] dart-lang/co19#3057. Add switch expression/statement tests for promotion (dart-lang/co19#3147) 2025-06-16 [email protected] dart-lang/co19#3057. Expect error in reachability_for_A03_t05.dart test. (dart-lang/co19#3132) 2025-06-16 [email protected] dart-lang/co19#3057. Add pattern assignment cases to C-style for tests (dart-lang/co19#3126) 2025-06-16 [email protected] Fixes dart-lang/co19#3227. Use `unspecified` error expectation (dart-lang/co19#3228) 2025-06-16 [email protected] dart-lang/co19#3180. Simplify JSAnyOperation tests. (dart-lang/co19#3223) Cq-Include-Trybots: luci.dart.try:analyzer-linux-release-try Change-Id: I8331e117e8f66469381fdefef59cdbef4a4fd06f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/435784 Commit-Queue: Alexander Thomas <[email protected]> Reviewed-by: Chloe Stefantsova <[email protected]> Reviewed-by: Alexander Thomas <[email protected]>
No description provided.